class Solution {
    int count = 0;
    int ret = 0;
    public int kthSmallest(TreeNode root, int k) {
        count = k;
        dfs(root);
        return ret;
    }
    public void dfs(TreeNode root) {
        //递归出口+剪枝
        if(root==null||count==0) {
            return;
        }
        //1.左子树
        dfs(root.left);
        //2.改值
        count--;
        if(count==0) {
            ret = root.val;
        }
        //剪枝
        if(count==0) {
            return;
        }
        //3.右子树
        dfs(root.right);
    }
}
